package com.sky.controller.admin;

import com.sky.mapper.MerchantMapper;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@Api(tags = "店铺状态接口")
@RequiredArgsConstructor
public class ShopController {
    private final RedisTemplate redisTemplate;
    private final static String REDIS_STATUS = "SHOP_STATUS";
    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置店铺状态")
    public Result<String> setStatus(@PathVariable Integer status){
        log.info("设置店铺状态为：{}",status==1?"营业中":"打烊中");
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }
    @GetMapping("/admin/shop/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(REDIS_STATUS);
        log.info("获取店铺状态为：{}",status==1?"营业中":"打烊中");
        return Result.success(status);
    }
    @GetMapping("/user/shop/status")
    @ApiOperation("用户端获取店铺状态")
    public Result<Integer> getShopStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(REDIS_STATUS);
        log.info("用户端获取店铺状态：{}",status==1?"营业中":"打烊中");
        return Result.success(status);
    }

    @Autowired
    private MerchantMapper merchantMapper;
    /**
     * 获取店铺电话
     */
    @ApiOperation("获取商家信息")
    @GetMapping("/user/shop/getMerchantInfo")
    public Result getMerchantInfo(){
        Merchant merchant = merchantMapper.getById(1L);
        String shopName = merchant.getShopName();
        String shopAddress = merchant.getShopAddress();
        String shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return Result.success(build);
    }
}
